#pragma once
#ifndef MATERIAL__SCENE__PARAMETERS__HH__
#define MATERIAL__SCENE__PARAMETERS__HH__
#include "LitEditorPrerequisites.h"

namespace Lit
{
	namespace Editor
	{
		namespace Material
		{
			class SceneParameters
			{
			public:
				struct Light
				{
					Light( const Ogre::Light::LightTypes & type_ = Ogre::Light::LT_POINT, const Vec3 & pos = Vec3(0.01f, 10.0f, 0.01f), const Vec3& look_at_pt = Vec3::ZERO, const Color& diff=Color::White, const Color& spec = Color::White );

					bool created() const;
					void destroy( RefPtr<Ogre::SceneManager> mgr );
					void create( RefPtr<Ogre::SceneManager> mgr, RefPtr<Ogre::SceneNode> node = RefPtr<Ogre::SceneNode>() );
					void sync(RefPtr<Ogre::SceneManager> mgr, RefPtr<Ogre::SceneNode> node = RefPtr<Ogre::SceneNode>());
						
					Ogre::Light * operator->();
					const Ogre::Light * operator->() const;
					Ogre::Light * operator*();
					const Ogre::Light * operator*() const;

					RefPtr<Ogre::Light> ptr;
					Vec3				position;
					Vec3				direction;
					Color				diffuse, 
										specular;
					Ogre::Light::LightTypes type;
				};
				struct Entity
				{
					Entity( Ogre::Entity * ent = NULL ) ;
					Entity( const std::string &mesh_name, const Vec3& scale_ = Vec3::UNIT_SCALE ) ;
						
					Ogre::Entity * operator->();
					const Ogre::Entity * operator->() const;
					Ogre::Entity * operator*();
					const Ogre::Entity * operator*() const;

					bool created() const;
					void destroy( RefPtr<Ogre::SceneManager> mgr );
					void create( RefPtr<Ogre::SceneManager> mgr, RefPtr<Ogre::SceneNode> node = RefPtr<Ogre::SceneNode>() );
					void sync( RefPtr<Ogre::SceneManager> mgr, RefPtr<Ogre::SceneNode> node = RefPtr<Ogre::SceneNode>() );

					RefPtr<Ogre::Entity> ptr;
					std::string mesh;
					Vec3 scale;
				};
				typedef std::vector<Light> LightList;

			public:
				SceneParameters( ) ;
				SceneParameters( const Color& ambient_, Ogre::ShadowTechnique shadows_, size_t numLights = 0 );
				~SceneParameters( ) ;
					
				void setMesh( const std::string &meshName, const Lit::Vec3& scale );

				Light& addLight( const Light& light );
				Light& setLight( size_t id, const Light& light );
				size_t getLightCount() const;
				void clearLights( );

				bool created() const;
				void destroy( );
				void create( RefPtr<Ogre::SceneManager> mgr );

				void sync(RefPtr<Ogre::SceneManager> mgr = RefPtr<Ogre::SceneManager>());
				void fitMeshInViewport( RefPtr<Ogre::Camera> cam, Real offset = 1.1f );

				RefPtr<Ogre::SceneManager> ptr;
				RefPtr<Ogre::SceneNode> node;

				Ogre::ShadowTechnique shadows;
				Entity entity;
				Color ambient;
				LightList lights;
			};
		};
	};
};

#endif